<!-- 普通检索 -->
<div class="option">
    <select name="" id="searchselect" class="borderNone">
        <script id="selectArr" type="text/html">
            <option value="{{:#data['value']}}">{{:#data['text']}}</option>
        </script>
    </select>
</div>

<input type="text" class="borderNone" id='searchWord' onkeypress="if (event.keyCode == 13) goMultiSearch();"
    placeholder="请输入关键词...">
<span class="similar" id="similarShow">
    <script id="searchMention" type="text/html">
        <a href="javascript:void(0);" onclick=goShowWord(this)>{{:#data}}</a>
        </script>
</span>
<!-- 检索 -->
<button class="borderNone s_Btn" id='searchBtn'>检索</button>
<script>
    $(function () {
        var timer;
        $('#similarShow').css('display', 'none');
        // 屏蔽掉拼音输入过程中会高频请求后台数据库
        var cpLock = true;
        $('#searchWord').on('compositionstart', function () {
            cpLock = false;
        });
        $('#searchWord').on('compositionend', function () {
            cpLock = true;
        });
        $('#searchWord').bind('input propertychange', function (e) {
            e.preventDefault();
            //获取input 元素,并实时监听用户输入
            //逻辑 如果输入框有值才调取 排除空格
            if (!$('#searchWord').val().replace(/\s/ig, "")) {
                timer = setTimeout(function () {
                    if (cpLock) {
                        if (cpLock) {
                                 // getSearchMention('');  
                        }
                    }
                }, 2000)
            } else {
                timer = setTimeout(function () {
                    if (cpLock) {
                        if (cpLock) {
                            getSearchMention($('#searchWord').val());
                        }
                    }
                }, 2000)
            }
        })
        //失去焦点
        $('#searchWord').blur(function (e) {
            e.preventDefault();
            //延迟关闭
            setTimeout(function () {
                // input框失去焦点，隐藏下拉框
                $('#similarShow').css('display', 'none');
            }, 200);
        })
        //获取焦点
        $('#searchWord').focus(function (e) {
            if (!($('#searchWord').val().replace(/\s/ig, ""))) {
                // getSearchMention('');
            }
        })
        function getSearchMention(keyWords) {
            var keyWords = base.replaceWord(keyWords);
            shared.ajaxPost(config.searchMention, { inputWord: keyWords }, function (res) {
                clearTimeout(timer)
                //如果搜索出来的值为空
                if (res && res.length) {
                    $('#similarShow').css('display', 'block');
                    core.useTemplateAuto('searchMention', res, {});
                } else {
                    $('#similarShow').css('display', 'none');
                }
            })
        }
    })
    function goShowWord(data) {
        $('#searchWord').val($(data).text());
        goMultiSearch()
    }
</script>